/**
 *
 * @Author: Marek Zakowicz <mazak (at) debian (dot) linux.org.pl>
 *
 * Copyright (c) 2005, 2006, 2007 Marek Zakowicz. All rights reserved.
 *
 * Licence: This code may be used, (re)distribute and/or modify under the terms one of the following two kinds of licence:
 *          1) as free software under GPL 3 (General Public Licence ver. 3 as published by the Free Software Foundation)
 *          2) as software under the terms individual licence from Marek Zakowicz
 *
 *          This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *          without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

package jsp2php;

class StaticBooleanTranslator extends TranslatorBase {
   public String name() {
      return "java.lang.Boolean";
   }

   public Translation translate_parseBoolean(Translation ... args) throws TranslatorException {
      validate_arg_no(1, "parseBoolean", args);
      validate_arg_type(JavaType.string(), "parseBoolean", args);
      Translation arg = args[1];
      /*
      if(arg.consistent) {
         return new Translation(String.format("%s == \"true\" ? true : false", arg.text), JavaType.bool(), false, true);
      }
      return new Translation(String.format("(%s) == \"true\" ? true : false", arg.text), JavaType.bool(), false, true);
      */
      return new Translation(String.format("%s == \"true\" ? true : false", arg.text), JavaType.bool(), false, true);
   }

   public Translation translate_toString(Translation ... args) throws TranslatorException {
      validate_arg_no(1, "toString", args);
      validate_arg_type(JavaType.bool(), "toString", args);
      Translation arg = args[1];
      /*
      if(arg.consistent) {
         return new Translation(String.format("%s ? \"true\" : \"false\"", arg.text), JavaType.string(), false, true);
      }
      return new Translation(String.format("(%s) ? \"true\" : \"false\"", arg.text), JavaType.string(), false, true);
      */
      return new Translation(String.format("%s ? \"true\" : \"false\"", arg.text), JavaType.string(), false, true);
   }
}

/**
 * @composed 1 - 1 BooleanValueTranslator
 */
class BooleanTranslator extends StaticBooleanTranslator implements ITypeTranslator {
   private static BooleanValueTranslator value_translator = new BooleanValueTranslator();

   static {
      ITypeTranslator tr = new BooleanTranslator();
      JavaType.add_type_translator( tr );
   }

   private BooleanTranslator() {}

   public IValueTranslator value_translator() {
      return value_translator;
   }
}

class BooleanValueTranslator extends StaticBooleanTranslator implements IValueTranslator {
   // TODO: (Un-)boxing przez delegacje do Bool
}
